package nickthissen.iracing.datamodels;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;

import com.google.gson.Gson;

public class Thread implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1290699851845508618L;
	
	public int Id;
	public int ForumId;
	public String Url;
	public String LastPageUrl;
	public int PageCount;
	public String Title;
	public String Author;
	public String AuthorUrl;
	public int Replies;
	public int Views;
	public long LastMessageTime;
	public String LastMessageUser;
	public String LastMessageUserUrl;  
	public String LatestReplyUrl;
    public String IconName;
    public boolean IsPoll;
    public boolean HasAttachments;
    public boolean IsWatching;
	
    public boolean isUnread()
    {
    	if (this.IconName == null) return false;
    	return this.IconName.contains("unread");
    }
    
	public static Thread fromJson(String json)
	{
		Gson g = new Gson();
		ThreadDataModel data = g.fromJson(json, ThreadDataModel.class);
		return data.d;
	}
	
	public static ArrayList<Thread> getListFromJson(String json)
	{
		Gson g = new Gson();
		ThreadListDataModel data = g.fromJson(json, ThreadListDataModel.class);
		return new ArrayList<Thread>(Arrays.asList(data.d));
	}
	
	private class ThreadDataModel
	{
		public Thread d;
	}
	
	private class ThreadListDataModel
	{
		public Thread d[];
	}
}
